<template>
	<scroll-view @scrolltolower="scrolltolower" :scroll-y="true" :class="pageClass" :style="pageStyle" v-if="pageReady">
		<moxi-nav :set="navSet"></moxi-nav>
		<view v-for="(list,key) in modData" :class="list.mod_class" :key="key" :style="list.css">
			<moxi-index v-if="list.name=='plugin_info_invite'" :list="list" >
		<view class="index">
			<view style="background-color: #fff;">
				<moxi-choose :field="choose" :top="navHeight"
				 @change="ch" v-model="info"></moxi-choose>
			</view>
			 <view class="search">
			 	<u-search placeholder="请输入内容" v-model="searchText" :showAction="false" bgColor="#fff"
			 		@search="searchBtn"></u-search>
			 </view>
			<view class="lists">
				<view class="list" v-for="(item, index) in listsData" :key="index" @click="goDetail(item)">
					<view class="top">
						<view class="left">{{item.title}}</view>
						<!-- <view class="right">{{item.province}}-{{item.city}}</view> -->
					</view>
					<view class="middle" style="display: flex;flex-direction: row;justify-content: space-between;">
						<view class="bottom">
							<view class="tab">{{item.type}}</view>
						</view>
						<view class="top" style="font-size: 13px;margin-top: 3px;">{{item.str}}</view>
					</view>
					<view class="footer">
						<view class="left" style="color: #666;">{{item.province}}-{{item.city}}</view>
						<view class="right" style="display: flex;flex-direction: row;color: #666;">
							<u-icon name="eye-fill" color="#666666"></u-icon>
							<view style="margin-left: 3px;"><text>{{item.view}}</text></view>
						</view>
					</view>
				</view>
						<view style="display: flex;flex-direction: row;justify-content: center;">
				<u-divider style="padding-bottom: 10px;" text="没有更多内容了" v-if="hasMore == false"></u-divider>
				</view>
			</view>
		</view>
	</moxi-index>
	<moxi-index v-else :list="list"></moxi-index>
	</view>
	<u-popup :show="show" @close="close" @open="open">
	            <view style="padding: 10px;display: flex;flex-direction: column;" v-if="con.id">
					<view v-if="msg.length" style="margin-bottom: 10px;">
						<u-alert :title="msg" type = "warning" ></u-alert>
					</view>
	               <view class="li">
					   <view class="li-title">
					   <u-icon name="man-add-fill" :color="app_color" size="18"></u-icon>
				
					   <text>招标企业：</text>
					   </view> 
					   <view class="li-con">{{con.company}}</view>
				   </view>
				   <view class="li">
					   <view class="li-title">
						   <view>
					   <u-icon name="list-dot" :color="app_color" size="18"></u-icon>
					   </view>
					   <text>招标类型：</text>
					   </view> 
					   <view class="li-con">{{con.type}}</view>
				   </view>
				   <view class="li">
				   					   <view class="li-title">
										   <view>
										   <u-icon name="map-fill" :color="app_color" size="18"></u-icon>
										   </view>
										   <text>所在城市：</text></view> 
				   					   <view class="li-con">{{con.province}}-{{con.city}}</view>
				   </view>
				   <view class="li">
				   					   <view class="li-title">
										   <view>
										   <u-icon name="calendar-fill" :color="app_color" size="18"></u-icon>
										   </view>
										   <text>截止时间：</text></view> 
				   					   <view class="li-con">招标文件获取截止5天后</view>
				   </view>
				   <view class="li">
				   					   <view class="li-title">
										   <view>
										   <u-icon name="attach" :color="app_color" size="18"></u-icon>
										   </view>
										   <text>招标文件</text></view> 
				   					   <view class="li-con">
										   <text :style="'color: '+app_color" @click="copy()">点击获取文件地址</text>
									   </view>
				   </view>
				   <view class="li">
				   					   <view class="li-title">
				   										   <view>
				   										   <u-icon name="more-circle" :color="app_color" size="18"></u-icon>
				   										   </view>
				   										   <text>招标说明</text></view> 
				   					   <view class="li-con" style="font-size: 14px;color: #666;flex-wrap: wrap;">
				   										  {{con.desc}}
				   									   </view>
				   </view>
	            </view>
			</u-popup>
			<moxi-tabbar :set="tabbar" v-if="tabbar.index_id"></moxi-tabbar>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				show:false,
				info: {
					page: 1,
					page_num: 5,
					province:"",
					city:"",
					distance:"",
					c_time:"",
					la:"",
					ln:"",
					start_time:"",
					search:"",
					start_daterange:[],
					type:""
				},
				con:{
					
				},
				isGet:false,
				searchText: '',
				listsData: [],
				hasMore: true,
				msg:"",
				choose: [ {
							name: '地区',
							type: 'city',
						}, {
							name: '筛选',
							type: 'choose',
							list: [
							{
								name: "招标开始时间",
								key: 'start_time',
								list: [{
										name: "不限",
										value: ""
									},
									{
										name: "正序",
										value: "asc"
									},
									{
										name: "倒序",
										value: "desc"
									}
								]
							},
							{
								name: "开始时间范围",
								key: 'start_daterange',
								list: []
							}
							]
						}],
						typeData:[],
						tagData:[],
			}
		},
		onLoad() {
			this.locationInit()
			setTimeout(()=>{
				if(!this.isGet){
					this.get()
				}
			},1000)
			
		},
		methods: {
			copy(){
				uni.setClipboardData({
				  data: this.con.url,
				  success: function () {
				    uni.showToast({
				      title: '已复制招标地址',
				      icon: 'success'
				    });
				  }
				});
			},
			close(){
				this.show = false
			},
			open(){
				this.show = true;
			},
			gengduo(){
				this.info.distance = 'asc';
				this.info.province = 'all';
				this.clear()
				this.get()
			},
			locationInit(call){
				let self = this;
				this.moxiGetLocation((res)=>{
					if(res.latitude){
						self.info.la = res.latitude;
						self.info.ln = res.longitude;
						if(this.isGet){
							self.clear();
							self.get()
						}else{
							self.get()
						}
						
					}else{
						// self.get()
						// self.getLocationShowBox()
					}
				})
			},
			getLocationShowBox(){
				let self = this;
				uni.showModal({
					title: '当前服务需要获取您的位置',
					content: '请将位置信息设置成“使用小程序时允许”',
					success: function (res) {
						if (res.confirm) {
							 self.openSet()
						} else if (res.cancel) {
							let page = getCurrentPages();
							if(page.length>1){
								uni.navigateBack();
							}else{
								uni.redirectTo({
									url: '/pages/index/index'
								});
							}
						}
					}
				});
			},
			openSet(){
				let self = this;
				uni.openSetting({
				  success(res) {
				   if(res.authSetting['scope.userLocation']){
					   self.locationInit()
				   }else{
					   self.getLocationShowBox()
				   }
				  }
				});
			},
			ch(v) {
				
				this.info = Object.assign(this.info, v);
				this.clear()
				this.get()
			},
			searchBtn() {
				this.clear()
				this.searchText = this.searchText.trim()
				this.info.search = this.searchText
				this.get()
			},
			clear(){
				this.hasMore = true
				this.info.page = 1
				this.listsData = []
			},
			scrolltolower(){
				if(this.hasMore){
					this.info.page++;
					this.get()
				}
			},
			zh(num) {
				if (num >= 1000) {
					return (num / 1000).toFixed(1) + 'K'
				} else {
					return num.toString()
				}
			},
			goDetail(list) {
				console.log(list);
				this.open()
				this.moxiPost('/plugin/info/user/qiye/get_invite_info',{id:list.id},
				 (data) =>{
					 this.msg = data.data.msg;
					 this.$set(this,'con',data.data.data)
				})
			},
			get() {
				let self = this
				this.moxiPost('/plugin/info/index/info/get_invite',this.info,
				 (data) =>{
					 if(!self.typeData.length){
						 self.typeData = data.typeData.map(item => ({
						  	name: item,
						  	value: item
						  }))
						  self.typeData.unshift({
						  	name: '全部',
						  	value: ''
						  })
						  self.choose.unshift(
						 	 {
						 	 	name: '分类',
						 	 	type: "list",
						 	 	key: "type",
						 	 	list: self.typeData
						 	 }
						 )
						 // self.tagData = data.tag.map(item => ({
						 //  	name: item,
						 //  	value: item
						 //  }))
						 // self.choose[3].list.unshift({
							//  name: "分类标签",
							//  key: 'check_tag',
							//  list: self.tagData
						 // })
					 }
					 
					
					if (data.data.allpage <= self.info.page) {
						self.hasMore = false;
					}
					for(let k in data.data.data){
						self.listsData.push(data.data.data[k])
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.li{
		display: flex;flex-direction: row;padding: 10px 0;border-bottom:1px #eee dashed
	}
	.li-title{
		display: flex;flex-direction: row;
	}
	.li text{width: 100px;flex-shrink: 0;font-size: 14px;margin-left: 3px;
	
	color: #666;
	}
	.li-con{
		flex: 1;color: #555;
	}
	.search {
		// width: 94%;
		// margin: 10px auto;
		padding: 12px;
		background-color: #f5f5f5;
	}
	.lists {
		width: 94%;
		margin: 0 auto;

		.list {
			margin-bottom: 10px;
			padding: 10px;
			background-color: #fff;

			&:nth-last-of-type(1) {
				margin-bottom: 0;
			}

			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left {
					font-size: 16px;
					font-weight: bold;
				}

				.right {
					font-size: 12px;color: #666;
				}
			}

			.middle {
				margin: 10px 0;
				font-size: 14px;
				color: #8f8f8f;

				.bottom {
					max-width: 70%;
					height: 24px;
					margin-top: 10px;
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					overflow: hidden;

					.tab {
						margin-right: 6px;
						padding: 4px;
						border-radius: 4px;
						background-color: #f2f2f2;
						font-size: 12px;

						&:nth-last-of-type(1) {
							margin-right: 0;
						}
					}
				}
			}

			.footer {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 12px;

				.right {
					color: #8f8f8f;
				}
			}
		}
	}

	.index {
	
		background-color: #f2f2f2;
		overflow: auto;
	}
</style>